package com.example.dessertstoressm.controller;

import com.example.dessertstoressm.Service.AccountService;
import com.example.dessertstoressm.Service.CatalogService;
import com.example.dessertstoressm.domain.Item;
import com.example.dessertstoressm.domain.Product;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;

import java.util.List;

@Controller
//@SessionAttributes(value={"productId","product","itemList"})
public class ProductFormController
{
    @Resource
    public CatalogService catalogService;

    @GetMapping("productForm")
    public String productForm(Model model, HttpServletRequest req)
    {

        String productId = req.getParameter("productId");
        Product product = catalogService.getProduct(productId);
        System.out.print("测试类别中商品的具体信息");
        List<Item> itemList = catalogService.getItemListByProduct(productId);


        HttpSession session = req.getSession();
        session.setAttribute("productId",productId);
        session.setAttribute("product" , product);
        session.setAttribute("itemList" , itemList);

        return"catalog/product";

    }
}
